package com.mid;

/**
 * Created by Lxk on 2020/2/24.
 */
public class Solution313 {

    public int nthSuperUglyNumber(int n, int[] primes) {
        int[] idx = new int[primes.length];
        int[] uglyNumberArr = new int[n];
        uglyNumberArr[0] = 1;
        for (int i = 1; i < n; i++) {
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < primes.length; k++) {
                if (primes[k] * uglyNumberArr[idx[k]] < min) {
                    min = primes[k] * uglyNumberArr[idx[k]];
                }
            }
            for (int k = 0; k < primes.length; k++) {
                if (primes[k] * uglyNumberArr[idx[k]] == min) {
                    idx[k]++;
                }
            }
            uglyNumberArr[i] = min;
        }
        return uglyNumberArr[n - 1];
    }

    public static void main(String[] args) {
        int[] arr = {2, 7, 13, 19};
        Solution313 solution313 = new Solution313();
        System.out.println(solution313.nthSuperUglyNumber(1, arr));
    }

}
